<script lang="ts" setup>
import { ref } from 'vue';
// import { BasicDrawer, useDrawerInner } from '@/components';
import { BasicDrawer, useDrawerInner } from 'hickey-ui';

defineOptions({ name: 'TestBasicDrawer' });

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(false);
const parentRecord = ref<any>({});

const [registerModal, { setDrawerProps, closeDrawer }] = useDrawerInner(async data => {
  setDrawerProps({ confirmLoading: true, loading: true });
  const timer = setTimeout(() => {
    setDrawerProps({ confirmLoading: false, loading: false });
    clearTimeout(timer);
  }, 1000);
});

async function handleCreate() {
  try {
    setDrawerProps({ confirmLoading: true, loading: true });
    console.log('============>测试');
  } catch (error) {
    console.warn(error);
  } finally {
    setDrawerProps({ confirmLoading: false, loading: false });
  }
}

function handleCancel() {
  if (isUpdate.value) emit('success');
  isUpdate.value = false;
  parentRecord.value = {}; // 清空
  closeDrawer();
}
</script>

<template>
  <BasicDrawer
    v-bind="$attrs"
    title="测试"
    :width="750"
    :min-height="500"
    :ok-text="isUpdate ? '保存' : '提交'"
    :show-footer="true"
    @register="registerModal"
    @close="handleCancel"
    @ok="handleCreate"
  >
    <div>123123123</div>
    <template #extra>
      <div>lkjlkjljl</div>
    </template>
  </BasicDrawer>
</template>
